/**
 * 
 */
package com.fwzc.giuseppe.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.fwzc.giuseppe.R;
import com.fwzc.giuseppe.base.BaseActivity;

/**
 * 
 * 类名称：LoginActivity 类描述：登录 创建人：何琳 创建时间：2015年8月13日 上午11:16:13
 * 
 * @version
 * 
 */
public class LoginActivity extends BaseActivity implements OnClickListener {

	private TextView forgetPw, login, register;
	private EditText username, password;
	private String name, pw;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_login);

		initBar();
		initView();
		initData();
	}

	private void initView() {
		forgetPw = (TextView) findViewById(R.id.for_pw);
		login = (TextView) findViewById(R.id.login_btn);
		register = (TextView) findViewById(R.id.register_btn);
		username = (EditText) findViewById(R.id.log_username);
		password = (EditText) findViewById(R.id.log_password);

	}

	private void initData() {
		iv_actionbar_side_left.setVisibility(View.VISIBLE);
		forgetPw.setOnClickListener(this);
		login.setOnClickListener(this);
		register.setOnClickListener(this);
		iv_actionbar_side_left.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		if (v == forgetPw) {
			Intent fpwIntent = new Intent(this, FindPwActivity.class);
			startActivity(fpwIntent);
		} else if (v == login) {
			name = username.getText().toString().trim();
			pw = password.getText().toString().trim();
			// 控制显示或隐藏输入法面板的类
			InputMethodManager imm = (InputMethodManager) this
					.getSystemService(Context.INPUT_METHOD_SERVICE);
			imm.hideSoftInputFromWindow(password.getWindowToken(), 0);
			if (name.equals("") || pw.equals("")) {
				Toast.makeText(getApplicationContext(), "请输入账号或密码！",
						Toast.LENGTH_SHORT).show();

				return;
			} else {
				sendRequest();
			}

		} else if (v == register) {
			Intent registerIntent = new Intent(this, RegisterActivity.class);
			startActivity(registerIntent);
		} else if (v == iv_actionbar_side_left) {
			finish();
		}

	}

	/**
	 * 登录请求
	 */
	private void sendRequest() {
		// TODO Auto-generated method stub

	}

}
